package com.woniu.cq.medical.controller;


import com.woniu.cq.medical.common.Result;
import com.woniu.cq.medical.controller.form.PrescriptionForm;
import com.woniu.cq.medical.entity.Prescription;
import com.woniu.cq.medical.service.PrescriptionInfoService;
import com.woniu.cq.medical.service.PrescriptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2020-09-08
 */
@RestController
@RequestMapping("/medical/prescription-info")
@CrossOrigin("*")//解决跨域问题
@Slf4j
public class PrescriptionInfoController {
    @Autowired
    private PrescriptionService prescriptionService;
    @Autowired
    private PrescriptionInfoService prescriptionInfoService;

    /**
     * 新增一条处方
     * 参数为前端传入的所有的处方详情
     * @return
     */
    @RequestMapping("insertPrescription")
    public Result insertPrescription(@RequestBody List<PrescriptionForm> prescriptionData){
        //调用新增处方的方法 获取新增的主键值
        Integer prescriptionId = prescriptionService.insertPrescription(prescriptionData);
        //新增处方详情
        prescriptionInfoService.insertPrescriptionInfo(prescriptionData,prescriptionId);
        return Result.success();
    }
}

